package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlan;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description NursingPlanController
 * @Author Lwj
 * @Date 2024-08-27-15:46
 */
@RequestMapping("/nursing/plan")
@RestController
@Slf4j
@Api(tags = "护理计划管理")
public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    /**
     * 护理计划管理
     *
     * @return
     */
    @GetMapping
    @ApiOperation(value = "查询所有护理计划")
    public ResponseResult<List<NursingPlan>> getNursingPlanAllInfor() {
        log.info("护理计划管理");
        List<NursingPlan> nursingPlan = nursingPlanService.getNursingPlanAllInfor();
        return success(nursingPlan);
    }

    /**
     * 新增
     *
     * @param nursingPlanDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "新增")
    @Transactional
    public ResponseResult AddNursingPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("新增{}", nursingPlanDto);
        nursingPlanService.AddNursingPlan(nursingPlanDto);
        return success();
    }

    /**
     * 条件分页查询
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/search")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult<PageResponse<NursingPlan>> projectData(
            @ApiParam(value = "护理计划名称") String name,
            @ApiParam(value = "当前页码") @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量") @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @ApiParam(value = "状态：0-禁用,1-启用") Integer status
    ) {
        log.info("条件分页查询！");
        PageResponse<NursingPlan> PageResponse = nursingPlanService.projectData(name, pageNum, pageSize, status);
        return success(PageResponse);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @ApiOperation("根据ID查询护理计划")
    @GetMapping("/{id}")
    public ResponseResult<NursingPlanVo> getNursingPlanById(
            @ApiParam(value = "护理计划ID", required = true)
            @PathVariable Long id) {
        return success(nursingPlanService.getById(id));
    }

    /**
     * 修改
     *
     * @param nursingPlanDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改")
    @Transactional
    public ResponseResult reSetPlan(@RequestBody NursingPlanDto nursingPlanDto) {
        log.info("修改{}", nursingPlanDto);
        nursingPlanService.reSetPlan(nursingPlanDto);
        return success();
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    @Transactional
    public ResponseResult deletePlan(@PathVariable @ApiParam(value = "要删除的id") Long id) {
        log.info("删除{}", id);
        nursingPlanService.deletePlan(id);
        return success();
    }

    /**
     * 启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用禁用")
    public ResponseResult ResetStatus(
            @ApiParam(value = "要修改项目状态的id") @PathVariable Long id,
            @ApiParam(value = "状态（0：禁用，1：启用）") @PathVariable int status) {
        log.info("项目启用禁用{}-{}", id, status);
        nursingPlanService.ResetStatus(id, status);
        return success();
    }

    @ApiOperation("查询所有护理计划")
    @GetMapping("/plan")
    public ResponseResult<List<NursingPlanVo>> getAllNursingPlan() {
        return ResponseResult.success(nursingPlanService.listAll());
    }


}
